<template>
    <div>
        <van-nav-bar title="购物车" left-text="返回" left-arrow @click-left="onClickLeft" />
        <div style="height: 45px;"></div>
         
        <div v-for="item in wch">
              <van-swipe-cell>
            <van-card :price="item.goods.goods_price" :title="item.goods.goods_name">
                <template #thumb>
                    <van-checkbox v-model="item.checked"></van-checkbox>
                    <img :src="item.goods.goods_big_logo ? item.goods.goods_big_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'"
                        alt="" style="width: 70px;height: 70px;">
                </template>
                <template #num>
                    <van-stepper v-model="value" theme="round" button-size="22" disable-input />
                </template>
            </van-card>
             <template #right>
                <van-button square text="删除" @click="sc(item.id)" type="danger" class="delete-button" />
            </template>
        </van-swipe-cell>
        </div>
          <van-submit-bar :price="sd" button-text="提交订单" @submit="onSubmit">
  <van-checkbox v-model="poo">全选</van-checkbox>
  <template #tip>
    你的收货地址不支持配送, <span @click="onClickLink">修改地址</span>
  </template>
</van-submit-bar>
    </div>
</template>

<script setup>
import { useCounterStore } from '@/stores/counter'
// 在组件内部的任何地方均可以访问变量 `store` ✨
const store = useCounterStore()
console.log(store.counter)
import { computed, ref } from 'vue'
let wch = ref([])

const ad = () => {
    wch.value = store.counter
}
ad()
const sc=(id)=>{
    store.counter=store.counter.filter(item=>item.id!=id)
    ad()
}
const poo=computed({
       get(){
        if(wch.value.length==0){
            return  false
        }
        else{
            return wch.value.every(item=>item.checked)
        }
        
       },
       
     set(val){
       return  wch.value.forEach(item=>item.checked=val)
     }
}
)
 const sd=computed(()=>{
      let sd=ref(0)
      let ok=wch.value.filter(item=>item.checked)
    ok.forEach(item=>{
sd.value=item.number*item.goods.goods_price
    })
    
    return sd.value*100
 })
</script>

<style lang="scss" scoped></style>